﻿using System;
using System.BusinessObjects.Data;
using Iesi.Collections.Generic;
using Blazing.BusinessObjects.Tagging;

namespace Blazing.BusinessObjects.Products
{
    [Serializable]
    public class Product : DataObject<Product>
    {
        public virtual int ID
        {
            get { return GetValue<int>("ID"); }
            set
            {
                BeginEdit();
                SetValue("ID", value);
            }
        }

        /// <summary>
        /// SKU
        /// </summary>
        public virtual string ProductCode
        {
            get { return GetValue<string>("ProductCode"); }
            set
            {
                BeginEdit();
                SetValue("ProductCode", value);
            }
        }

        public virtual string Name
        {
            get
            {
                return GetValue<string>("Name");
            }
            set
            {
                BeginEdit();
                SetValue("Name", value);
            }
        }

        public virtual string Description
        {
            get { return GetValue<string>("Description"); }
            set
            {
                BeginEdit();
                SetValue("Description", value);
            }
        }

        public virtual decimal PriceNett
        {
            get { return GetValue<decimal>("PriceNett"); }
            set
            {
                BeginEdit();
                SetValue("PriceNett", value);
            }
        }

        public virtual decimal Price
        {
            get { return GetValue<decimal>("Price"); }
            set
            {
                BeginEdit();
                SetValue("Price", value);
            }
        }

        /// <summary>
        /// Number of units in stock
        /// </summary>
        public virtual int InStock
        {
            get { return GetValue<int>("InStock"); }
            set
            {
                BeginEdit();
                SetValue("InStock", value);
            }
        }

        /// <summary>
        /// Stock amount is correct as of this date, does not take into account
        /// orders before this date
        /// </summary>
        public virtual DateTime StockDate
        {
            get { return GetValue<DateTime>("StockDate"); }
            set
            {
                BeginEdit();
                SetValue("StockDate", value);
            }
        }

        /// <summary>
        /// This product is limited by the amount of stock, else can be sold infinitely
        /// </summary>
        public virtual bool HasInventory
        {
            get { return GetValue<bool>("HasInventory"); }
            set
            {
                BeginEdit();
                SetValue("HasInventory", value);
            }
        }

        public virtual bool Active
        {
            get { return GetValue<bool>("Active"); }
            set
            {
                BeginEdit();
                SetValue("Active", value);
            }
        }

        [NonSerialized]
        private ISet<TaxonomyTag> _taxonomyTags = new HashedSet<TaxonomyTag>();
        public virtual ISet<TaxonomyTag> TaxonomyTags
        {
            get
            {
                return _taxonomyTags;
            }
            set
            {
                BeginEdit();
                _taxonomyTags = value;
            }
        }

        public virtual DateTime RowStamp
        {
            get
            {
                return GetValue<DateTime>("RowStamp");
            }
            set
            {
                SetValue("RowStamp", value);
            }
        }
    }
}
